package org.darcy.service.sys.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.darcy.dao.sys.SysFileMapper;
import org.darcy.entity.sys.SysFile;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.service.sys.SysFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * SysFile服务实现
 */
@Service
@Transactional
public class SysFileServiceImpl extends GenericServiceImpl<SysFile> implements SysFileService {

	@Autowired
	private SysFileMapper mapper;

	@Override
	public SysFile getDetail(Integer id) {
		SysFile record = mapper.selectById(id);
		return record;
	}

	@Override
	public PageData<SysFile> page(PageParam param) {
		PageData<SysFile> data = super.getPageData(param);
		return data;
	}

	@Override
	public List<String> getFilePathList(String ids) {
		List<SysFile> list = super.getByIds(Arrays.asList(ids.split(",")));
		List<String> result = list.stream().map(a -> a.getUrl()).collect(Collectors.toList());
		return result;
	}

	@Override
	public String getFileIdList(List<String> urlList) {
		QueryWrapper<SysFile> q = new QueryWrapper<SysFile>();
		q.in("url", urlList);
		List<SysFile> list = this.getList(q);
		String result = list.stream().map(a -> a.getId().toString()).collect(Collectors.joining(","));
		return result;
	}

}
